# This file is used for Unity Plugin build

cmake_minimum_required(VERSION 3.16.5)
project(frameflowUnityPlugin LANGUAGES C CXX)

include(target_setup.cmake)
set(PLUGIN_NAME frameflowPlugin)
set(FF_UNITY_NATIVE_PLUGIN_EDITOR_HEADERS ./PluginAPI)

#>>> Unity plugin
link_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/lib
)

file(GLOB PLUGIN_FF_GL_SRC
    src/wrapper/ff_wrapper_gl.cpp
    src/plugin_api_gl.cpp
)

file(GLOB PLUGIN_FF_VK_SRC
    src/wrapper/ff_wrapper_vk.cpp
    src/plugin_api_vk.cpp
)

add_library(${PLUGIN_NAME} SHARED
    src/plugin_main.cpp
    src/wrapper/ff_plugin.cpp
    ${PLUGIN_FF_GL_SRC}
    ${PLUGIN_FF_VK_SRC}
)

target_include_directories(${PLUGIN_NAME} PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/src
    ${CMAKE_CURRENT_SOURCE_DIR}/src/wrapper
    ${CMAKE_CURRENT_SOURCE_DIR}/src/platform
    ${CMAKE_CURRENT_SOURCE_DIR}/frame_prediction/include
    ${FF_UNITY_NATIVE_PLUGIN_EDITOR_HEADERS}
)

target_compile_definitions(${PLUGIN_NAME} PRIVATE
    -DFF_NO_PROTOTYPES
)

frameflow_setup_target(${PLUGIN_NAME})

if(ANDROID)
    target_sources(${PLUGIN_NAME} PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/dynamic_library.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/gles32_loader.cpp
    )

    target_link_libraries(${PLUGIN_NAME} PRIVATE
        log
    )
endif()

install(TARGETS ${PLUGIN_NAME}
    ARCHIVE DESTINATION bin
    LIBRARY DESTINATION bin
    RUNTIME DESTINATION bin
)
